#!/usr/bin/ruby
# -*- ruby -*-
#
# http://programmingpraxis.com/2012/11/09/taxicab-numbers/

require 'set'

ns = ARGV.empty? ? [1729] : ARGV.map { |s| s.to_i }

t = (0 .. ns.max).to_a.inject({}) { |r, i| r.merge(i * i * i => i) }

ns.each do |n|
    r = t.inject(Set.new) { |r, (ac, a)| t.has_key?(n - ac) ? r << [a, t[n - ac]].sort : r}

    r.each do |(a, b)|
        puts "#{n} = #{a}^3 + #{b}^3"
    end
end
